// import axios from 'axios'
// const serialize = $('.add-form').serialize()
document.querySelector('button').addEventListener('click', function () {
  const form = document.querySelector('form')
  const formData = serialize(form, { hash: true, empty: true })
  const { mobile, code } = formData
  if (!(/^1[3-9]\d{9}/.test(mobile))) {
    alert('手机号不符合')
    return
  }
  if (!(/\d{6}/.test(code))) {
    alert('验证码不符合')
    console.log(formData);
    return
  }
  axios.defaults.baseURL = 'https://geek.itheima.net'
  const data = JSON.stringify({
    "mobile": mobile,
    "code": code
  });

  const config = {
    method: 'post',
    url: '/v1_0/authorizations',
    headers: {
      'Content-Type': 'application/json'
    },
    data: data
  };

  axios(config)
    .then(function (response) {
      console.log(response.data.data.token);
      localStorage.setItem('token', response.data.data.token)
      location.href = '../home/inroll.html'
    })
    .catch(function (error) {
      console.log(error + "有误");
    });

})
// import '../abliz/login.css'